package com.group525.cloudef.mapper.doctor;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.group525.cloudef.Dao.doctor.DiagnoseDao;
import com.group525.cloudef.common.CommonResult;
import com.group525.cloudef.entity.doctor.DUser;
import com.group525.cloudef.entity.user.UHazard;
import com.group525.cloudef.entity.user.UReport;
import com.group525.cloudef.entity.user.Uinfectious;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DdiagnoseMapper extends BaseMapper<DUser> {
    @Select("select user_id, tag, hospital_time from d_patient where doctor_id=#{doctor_id} and tag=0")
    List<DiagnoseDao> getPatientId(Long doctor_id);
    @Select("select name, gender, age from u_user where id=#{user_id}")
    DiagnoseDao getPatient(Long user_id);

    @Insert("insert into u_infectious(id, disease_name, user_id, doctor_id, classify, " +
            "onset, diagnose_time, report_time, info) values (#{id}, #{disease_name}, " +
            "#{user_id}, #{doctor_id}, #{classify}, #{onset}, #{diagnose_time}, #{report_time}, #{info})")
    Integer createInfectious(Uinfectious uinfectious);
    @Select("select count(*) from u_infectious")
    Integer getInfectiousCount();

    @Insert("insert into u_hazard(no, user_id, doctor_id, hazard, info, time) values " +
            "(#{no}, #{userId}, #{doctorId}, #{hazard}, #{info}, #{time})")
    Integer submitHazard(UHazard uHazard);
    @Select("select count(*) from u_hazard")
    Integer getHazardCount();

    @Insert("insert into u_report(report_no, doctor_id, user_id, disease_name, check_intro," +
            "image_type, image_info, diagnose, create_time, update_time) values " +
            "(#{reportNo}, #{doctorId}, #{userId}, #{diseaseName}, #{checkIntro}, #{imageType}," +
            "#{imageInfo}, #{diagnose}, #{createTime}, #{updateTime})")
    Integer submitReport(UReport uReport);
    @Select("select max(report_no) from u_report")
    Long getReportNo();
    @Update("update u_image set report_no=#{reportNo} where user_id=#{userId} and report_no=0")
    void imageAddReport(Long reportNo, Long userId);
    @Update("update d_patient set tag=1 where user_id=#{userId} and doctor_id=#{doctorId}")
    void updateRelate(Long userId, Long doctorId);
}